package com.sky.config;

import com.sky.properties.ObjectStorageProperties;
import com.sky.utils.AliOssUtil;
import com.sky.utils.TxCosUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Content: 文件上传配置类
 * @Author: Asen
 * @Date: 2023/8/31 22:14
 */
@Slf4j
@Configuration
public class OssConfiguration {
    @Bean
    @ConditionalOnMissingBean//在没有这个类的情况下才会去创建
    public AliOssUtil aliOssUtil(ObjectStorageProperties objectStorageProperties){
        log.info("阿里云文件上传：{}", objectStorageProperties);
        return new AliOssUtil(objectStorageProperties.getAliEndpoint(),
                objectStorageProperties.getAliAccessKeyId(),
                objectStorageProperties.getAliAccessKeySecret(),
                objectStorageProperties.getAliBucketName());
    }

    @Bean
    @ConditionalOnMissingBean
    public TxCosUtil txCosUtil(ObjectStorageProperties objectStorageProperties){
        log.info("腾讯云文件上传：{}", objectStorageProperties);
        return new TxCosUtil(objectStorageProperties.getTEndpoint(),
                objectStorageProperties.getTAccessKeyId(),
                objectStorageProperties.getTAccessKeySecret(),
                objectStorageProperties.getTBucketName());
    }
}
